package fr.vahren.dotastrat.gui;

import com.trolltech.qt.gui.QGridLayout;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QPushButton;
import com.trolltech.qt.gui.QWidget;

import fr.vahren.dotastrat.Main;
import fr.vahren.dotastrat.model.D2SCreepType;

public class D2SZoneWidget extends QWidget {
	private int zoneId;

	private QLabel radiantHeros = new D2SLabel("0", "green", 9);
	private QLabel direHeros = new D2SLabel("0", "red", 9);
	private QLabel radiantCreeps = new D2SLabel("0", "green", 8);
	private QLabel direCreeps = new D2SLabel("0", "red", 8);
	private QLabel radiantWard = new D2SLabel("OW", "green", 6);
	private QLabel direWard = new D2SLabel("OW", "red", 6);
	private QWidget creeps = new QWidget();
	private QLabel radiantActiveAbility = new D2SLabel("!", "green", 9);
	private QLabel direActiveAbility = new D2SLabel("!", "red", 9);
	private QPushButton chooseZone = new QPushButton("SELECT");

	public D2SZoneWidget(int x, int y, QWidget parent, int id) {
		super(parent);
		zoneId = id;
		QGridLayout layout = new QGridLayout();
		setLayout(layout);
		layout.setContentsMargins(0, 0, 0, 0);
		layout.setVerticalSpacing(0);
		layout.setHorizontalSpacing(0);
		layout.addWidget(radiantHeros, 0, 0, 1, 2);
		layout.addWidget(direHeros, 0, 4, 1, 2);
		layout.addWidget(radiantWard, 0, 2);
		layout.addWidget(direWard, 0, 3);
		layout.addWidget(radiantCreeps, 2, 0);
		layout.addWidget(direCreeps, 2, 5);
		layout.addWidget(radiantActiveAbility, 1, 0, 1, 2);
		layout.addWidget(direActiveAbility, 1, 4, 1, 2);
		layout.addWidget(chooseZone, 1, 2, 1, 2);
		layout.addWidget(creeps, 2, 2, 1, 2);
		setFixedSize(60, 50);
		move(x, y);

		// listeners
		chooseZone.clicked.connect(this, "chooseZone(boolean)");
	}

	public void update(int rHeros, int dHeros, boolean rWards, boolean dWards,
			boolean rObs, boolean dObs, int rCreeps, int dCreeps,
			boolean rActive, boolean dActive, boolean choose,
			D2SCreepType creep1, D2SCreepType creep2) {
		radiantHeros.setText(String.valueOf(rHeros));
		direHeros.setText(String.valueOf(dHeros));
		radiantWard.setText((rWards ? "W" : "") + (rObs ? "O" : ""));
		direWard.setText((dWards ? "W" : "") + (dObs ? "O" : ""));
		radiantCreeps.setText(String.valueOf(rCreeps));
		direCreeps.setText(String.valueOf(dCreeps));
		radiantActiveAbility.setText(rActive ? "!" : "");
		direActiveAbility.setText(dActive ? "!" : "");

	}

	public void chooseZone(boolean b) {
		Main.getWindow().chooseZone(zoneId);
	}

}
